package extendsClass

/**
  * Person
  *
  * @author zhangyimin
  * @date 2018-09-14 下午5:26
  * @version 1.0
  */
//父类
class Person(val id: Int, val name: String) {
  def sayHello(): String = "Hello " + name + " your ID is " + id
}

//子类
class Son(override val name: String, override val id: Int, age: Int) extends Person(id, name) {
  //重写父类的方法
  override def sayHello(): String = super.sayHello()+"加工一下"
}


object Test {

  def main(args: Array[String]): Unit = {

    var p = new Person(1, "tom")
    println(p.sayHello())
    //子类继承父类的调用
    var s: Person = new Son("mary", 2, 18)
    println(s.sayHello())
    //匿名函数相当于JAVA中的接口
    var ps:Person=new Person(88888,"mike"){
      override def sayHello(): String = "匿名函数修改了方法=====>"+name+"__________"+id
    }
    println(ps.sayHello())





  }

}









